import 'package:flutter/material.dart';
import 'package:junyeyishu/ui/mine/widget/QGMinePurchaseOrderCell.dart';
import 'package:junyeyishu/utils/utils.dart';

import 'QGMineOrderPage.dart';

class QGMinePurchaseOrderPage extends QGMineOrderPage {
  const QGMinePurchaseOrderPage({super.key});
  @override
  State<QGMineOrderPage> createState() => QGMinePurchaseOrderPageState();
}

class QGMinePurchaseOrderPageState extends QGMineOrderPageState {
  @override
  void initState() {
    myBought_url = url_ask_getMyOrderList;

    super.initState();
    items = ["求购中", "已成交", "已取消", "已卖出"];
    title = "求购订单";
  }

  @override
  listParam() {
    switch (type) {
      case 0:
        return {"order_status": 4};
      case 1:
        return {"order_status": 6};
      case 2:
        return {"order_status": 2};
      case 3:
        return {"order_status": 6};
      default:
        break;
    }

    return {};
  }

  @override
  itemBuilder(context, index, data) {
    data ??= {};
    data["status"] = type;

    return GestureDetector(
        onTap: () {
          Navigator.of(context)
              .pushNamed(PageMyPurchaseOrderDetail, arguments: data)
              .then((value) {
            onRefresh();
          });
        },
        child: QGMinePurchaseOrderCell(data: data));
  }

  @override
  onSwitch(index) {
    type = index;
    list = null;
    if (index == 3) {
      listURL = url_ask_getMySellOrderList;
    } else {
      listURL = url_ask_getMyOrderList;
    }

    listKey = "list";
    setState(() {});
    onRefresh();
  }
}
